<?php
namespace Common\Controller;
use Think\Controller;

/**
 * Person Data Model Proxy Class
 *
 * @package Common\Controller
 * @author lythesia
**/
class PersonController extends Controller {

// {{{ shared functions
  /**
   * Get Person data by `person_id`
   *
   * @param  string movie_id
   * @param  string fields(optional)
   * @return array query result
   * @author lythesia
   **/
  public function getPersonById($id, $field='') {
    $Person = M('Person');
    $data = $Person->field($field)->find($id);
    return $data;
  }


  /**
   * Get Person and related data by `person_id`
   *
   * @param  string person_id
   * @param  array options
   * @param  string fields(optional)
   * @return array query result
   * @author lythesia
   **/
  public function getPersonRelById($id, $opt, $field='') {
    $Person = D('Person');
    $data = $Person->field($field)->relation($opt['rel'])->find($id);
    return $data;
  }


  /**
   * Get Persons data by conditions
   *
   * @param  array conditions
   * @param  array options
   * @param  string field(optional)
   * @param  boolean if need count query results(optional, default false)
   * @return array query result
   * @author lythesia
   **/
  public function getPersonsByCond($cond, $opt, $field='', $if_count = false) {
    $Person = D('Person');
    $where = parse_complex_cond($cond);

    $data = $Person->field($field)->limit($opt['offset'], $opt['size'])->order($opt['order'])->relation($opt['rel'])->where($where)->select();

    if($if_count) {
      $count = $Person->where($where)->count();
      return array($count, $data);
    }
    else return $data;
  }
// }}}


// {{{ inter-module functions
// }}}
}
